package com.example.producer.produce;

import com.alibaba.fastjson.JSON;
import com.example.producer.entity.Order;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 延迟队列实现二: 需要安装插件
 * @author shuc001
 * @Date 2018/9/27 下午4:26
 */
@Component
public class DelaySend2 {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void send(Order order){
        rabbitTemplate.convertAndSend("delay_ex","delay.#", JSON.toJSONString(order),message -> {
            message.getMessageProperties().setHeader(MessageProperties.X_DELAY,5000);
            return message;
        },new CorrelationData(order.getId()));
    }
}
